package com.ruoyi.system.service.zhaungxiuservice.shopService.impl;

import com.ruoyi.system.domain.zhuangxiumain.shopMain.ProductCategory;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.ProductCategoryMapper;
import com.ruoyi.system.service.zhaungxiuservice.shopService.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {

    @Autowired(required = false)
    private ProductCategoryMapper productCategoryMapper;


    @Override
    public List<ProductCategory> findAllList(ProductCategory productCategory) {
        return productCategoryMapper.findAllList(productCategory);
    }

    @Override
    public int insertCategory(ProductCategory productCategory) {

        productCategory.setCategoryLevel(1);
        productCategory.setCategoryStatus("1");
        productCategory.setModifiedTime(new Date());
        return productCategoryMapper.insertCategory(productCategory);
    }

    @Override
    public int deleteCategoryByIds(Long[] categoryId) {
        return productCategoryMapper.deleteCategoryByIds(categoryId);
    }

    @Override
    public int updataByOneId(ProductCategory productCategory) {
//        productCategory.setCategoryStatus(0);
        return productCategoryMapper.updataByOneId(productCategory);
    }



    //        <!--*************  以上是忘了干啥的了  ***************-->
//    <!--***************TODO 以下是店铺中分类用的 *********************-->

    @Override
    public List<ProductCategory> ProductCategoryList(ProductCategory productCategory) {
        return productCategoryMapper.ProductCategoryList(productCategory);
    }


    @Override
    public ProductCategory selectProductCategoryById(Integer categoryId) {
        return productCategoryMapper.selectProductCategoryById(categoryId);
    }

    @Override
    public List<ProductCategory> selectProductCategoryList(Integer brandId) {
        return productCategoryMapper.selectProductCategoryList(brandId);
    }

    @Override
    public int insertCommonCategory(ProductCategory productCategory) {
        Integer commennumbar = productCategory.getCommennumbar();
        System.err.println("commennumbar ***------------****************************----------**" +commennumbar);
        productCategory.setBrandId(commennumbar);  // brand_info表的自增ID

        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i=0;i<8;i++){
            stringBuilder.append(random.nextInt(10));
        }
        String numCode1 =stringBuilder.toString();
        productCategory.setCategoryCode(numCode1); // 分类编号

        productCategory.setStatusType("0");
        productCategory.setCategoryLevel(2);  //层级
        productCategory.setCategoryStatus("1"); // 1启动 0禁用
        productCategory.setCategoryType("1"); //  0表示建房主材类别,1表示家居建材类别
        productCategory.setModifiedTime(new Date());
        return productCategoryMapper.insertProductCategory(productCategory);
    }

    @Override
    public int insertCommonHouse(ProductCategory productCategory) {
        Integer commennumbar = productCategory.getCommennumbar();
        System.err.println("commennumbar ***------------****************************----------**" +commennumbar);
        productCategory.setBrandId(commennumbar);  // brand_info表的自增ID

        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i=0;i<8;i++){
            stringBuilder.append(random.nextInt(10));
        }
        String numCode1 =stringBuilder.toString();
        productCategory.setCategoryCode(numCode1); // 分类编号

        productCategory.setStatusType("0");
        productCategory.setCategoryLevel(2);  //层级
        productCategory.setCategoryStatus("1"); // 1启动 0禁用
        productCategory.setCategoryType("0"); //  0表示建房主材类别,1表示家居建材类别
        productCategory.setModifiedTime(new Date());
        return productCategoryMapper.insertProductCategory(productCategory);
    }

    @Override
    public List<ProductCategory> findAllCommenOne() {
        return productCategoryMapper.findAllCommenOne();
    }

    @Override
    public List<ProductCategory> findAllCommenOneZi(Integer parentId) {
        return productCategoryMapper.findAllCommenOneZi(parentId);
    }

    @Override
    public List<ProductCategory> CategoryListHouse(ProductCategory productCategory) {
        return productCategoryMapper.CategoryListHouse(productCategory);
    }

    @Override
    public List<ProductCategory> findAllCommenTwo() {
        return productCategoryMapper.findAllCommenTwo();
    }

    @Override
    public List<ProductCategory> findAllCommenTwoZi(Integer parentId) {
        return productCategoryMapper.findAllCommenTwoZi(parentId);
    }


//    TODO: 以下是 超管分类的

    @Override
    public List<ProductCategory> supertfindAllListOne(ProductCategory productCategory) {
        return productCategoryMapper.supertfindAllListOne(productCategory);
    }

    @Override
    public List<ProductCategory> supertfindAllListOneZi(Integer parentId) {
        return productCategoryMapper.supertfindAllListOneZi(parentId);
    }

    @Override
    public List<ProductCategory> supertfindAllListTwo(ProductCategory productCategory) {
        return productCategoryMapper.supertfindAllListTwo(productCategory);
    }

    @Override
    public List<ProductCategory> supertfindAllListTwoZi(Integer parentId) {
        return productCategoryMapper.supertfindAllListTwoZi(parentId);
    }

    @Override
    public int updateCategorySuper(ProductCategory productCategory) {
        return productCategoryMapper.updateCategorySuper(productCategory);
    }

    @Override
    public int deleteOneSuperByIds(Integer[] categoryId) {
        return productCategoryMapper.deleteOneSuperByIds(categoryId);
    }

    @Override
    public int insertProductCategory(ProductCategory productCategory) {
        return productCategoryMapper.insertProductCategory(productCategory);
    }

    @Override
    public int insertProductCategoryZi(ProductCategory productCategory) {
        Integer numtype = productCategory.getNumtype();
        System.err.println("*******"+ numtype);
        if(numtype == 1){
            StringBuilder stringBuilder = new StringBuilder();
            Random random = new Random();
            for (int i=0;i<8;i++){
                stringBuilder.append(random.nextInt(10));
            }
            String numCode =stringBuilder.toString();
            productCategory.setCategoryCode(numCode);
            Integer num1 = productCategory.getNum1();
            System.err.println("*******"+ num1);
            productCategory.setParentId(num1);
            productCategory.setCategoryLevel(2);  //层级
            productCategory.setCategoryType("1"); // 0表示建房主材类别,1表示家居建材类别
            productCategory.setCategoryStatus("1"); // 1启动 0禁用
            productCategory.setModifiedTime(new Date());
            productCategory.setDelFlag("0");
            return productCategoryMapper.insertProductCategoryZi(productCategory);
        }else if(numtype == 0) {
            StringBuilder stringBuilder = new StringBuilder();
            Random random = new Random();
            for (int i=0;i<8;i++){
                stringBuilder.append(random.nextInt(10));
            }
            String numCode =stringBuilder.toString();
            productCategory.setCategoryCode(numCode);
            Integer num1 = productCategory.getNum1();
            System.err.println("*******"+ num1);
            productCategory.setParentId(num1);
            productCategory.setCategoryLevel(2);  //层级
            productCategory.setCategoryType("0"); // 0表示建房主材类别,1表示家居建材类别
            productCategory.setCategoryStatus("1"); // 1启动 0禁用
            productCategory.setModifiedTime(new Date());
            productCategory.setDelFlag("0");
            return productCategoryMapper.insertProductCategoryZi(productCategory);
        }
        return productCategoryMapper.insertProductCategoryZi(productCategory);
    }


}
